﻿using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using LibHuman;
namespace Human
{
	public class frmDanhSachConCB : System.Windows.Forms.Form
	{
		private AccessData mDB = new AccessData(); 
		private DataSet ds =new DataSet();
        Language lan = new Language();
        string sql = "", m_user = "", title = "", ReportName = "",s_bophan="",user_dn="";		
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.RadioButton rdbLonHonBang;
		private System.Windows.Forms.RadioButton rdbLonNhoBang;
		private System.Windows.Forms.RadioButton rdbBang;
		private System.Windows.Forms.Button butThoat;
		private System.Windows.Forms.Button butIn;
		private System.Windows.Forms.Button butXem;
		private System.Windows.Forms.NumericUpDown lsbChonTuoi;
		private System.ComponentModel.Container components = null;

		public frmDanhSachConCB(string s_makp,string s_userdn)
		{
			InitializeComponent();
            lan.Read_Language_to_Xml(this.Name.ToString(), this);
            lan.Changelanguage_to_English(this.Name.ToString(), this);
            s_bophan = s_makp;
            user_dn = s_userdn;
		}

		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(frmDanhSachConCB));
            this.label1 = new System.Windows.Forms.Label();
            this.groupBox1 = new System.Windows.Forms.GroupBox();
            this.rdbLonHonBang = new System.Windows.Forms.RadioButton();
            this.rdbLonNhoBang = new System.Windows.Forms.RadioButton();
            this.rdbBang = new System.Windows.Forms.RadioButton();
            this.label2 = new System.Windows.Forms.Label();
            this.lsbChonTuoi = new System.Windows.Forms.NumericUpDown();
            this.butThoat = new System.Windows.Forms.Button();
            this.butIn = new System.Windows.Forms.Button();
            this.butXem = new System.Windows.Forms.Button();
            this.groupBox1.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.lsbChonTuoi)).BeginInit();
            this.SuspendLayout();
            // 
            // label1
            // 
            this.label1.ForeColor = System.Drawing.Color.DarkBlue;
            this.label1.Location = new System.Drawing.Point(13, 27);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(58, 13);
            this.label1.TabIndex = 0;
            this.label1.Text = "Chọn tuổi :";
            this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // groupBox1
            // 
            this.groupBox1.Controls.Add(this.rdbLonHonBang);
            this.groupBox1.Controls.Add(this.rdbLonNhoBang);
            this.groupBox1.Controls.Add(this.rdbBang);
            this.groupBox1.Location = new System.Drawing.Point(74, 56);
            this.groupBox1.Name = "groupBox1";
            this.groupBox1.Size = new System.Drawing.Size(198, 39);
            this.groupBox1.TabIndex = 2;
            this.groupBox1.TabStop = false;
            // 
            // rdbLonHonBang
            // 
            this.rdbLonHonBang.Checked = true;
            this.rdbLonHonBang.ForeColor = System.Drawing.Color.Navy;
            this.rdbLonHonBang.Location = new System.Drawing.Point(12, 12);
            this.rdbLonHonBang.Name = "rdbLonHonBang";
            this.rdbLonHonBang.Size = new System.Drawing.Size(56, 16);
            this.rdbLonHonBang.TabIndex = 1;
            this.rdbLonHonBang.TabStop = true;
            this.rdbLonHonBang.Text = " >= ";
            this.rdbLonHonBang.KeyDown += new System.Windows.Forms.KeyEventHandler(this.rdbLonHonBang_KeyDown);
            // 
            // rdbLonNhoBang
            // 
            this.rdbLonNhoBang.ForeColor = System.Drawing.Color.Navy;
            this.rdbLonNhoBang.Location = new System.Drawing.Point(74, 12);
            this.rdbLonNhoBang.Name = "rdbLonNhoBang";
            this.rdbLonNhoBang.Size = new System.Drawing.Size(56, 16);
            this.rdbLonNhoBang.TabIndex = 2;
            this.rdbLonNhoBang.Text = " <= ";
            this.rdbLonNhoBang.KeyDown += new System.Windows.Forms.KeyEventHandler(this.rdbLonNhoBang_KeyDown);
            // 
            // rdbBang
            // 
            this.rdbBang.ForeColor = System.Drawing.Color.Navy;
            this.rdbBang.Location = new System.Drawing.Point(132, 12);
            this.rdbBang.Name = "rdbBang";
            this.rdbBang.Size = new System.Drawing.Size(56, 16);
            this.rdbBang.TabIndex = 3;
            this.rdbBang.Text = " = ";
            this.rdbBang.KeyDown += new System.Windows.Forms.KeyEventHandler(this.rdbBang_KeyDown);
            // 
            // label2
            // 
            this.label2.ForeColor = System.Drawing.Color.Navy;
            this.label2.Location = new System.Drawing.Point(13, 71);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(58, 13);
            this.label2.TabIndex = 3;
            this.label2.Text = "Điều kiện :";
            this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // lsbChonTuoi
            // 
            this.lsbChonTuoi.ForeColor = System.Drawing.SystemColors.HotTrack;
            this.lsbChonTuoi.Location = new System.Drawing.Point(74, 24);
            this.lsbChonTuoi.Maximum = new decimal(new int[] {
            40,
            0,
            0,
            0});
            this.lsbChonTuoi.Minimum = new decimal(new int[] {
            1,
            0,
            0,
            0});
            this.lsbChonTuoi.Name = "lsbChonTuoi";
            this.lsbChonTuoi.Size = new System.Drawing.Size(64, 20);
            this.lsbChonTuoi.TabIndex = 0;
            this.lsbChonTuoi.Value = new decimal(new int[] {
            15,
            0,
            0,
            0});
            this.lsbChonTuoi.KeyDown += new System.Windows.Forms.KeyEventHandler(this.lsbChonTuoi_KeyDown);
            // 
            // butThoat
            // 
            this.butThoat.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.butThoat.ForeColor = System.Drawing.Color.Navy;
            this.butThoat.Image = ((System.Drawing.Image)(resources.GetObject("butThoat.Image")));
            this.butThoat.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.butThoat.Location = new System.Drawing.Point(190, 110);
            this.butThoat.Name = "butThoat";
            this.butThoat.Size = new System.Drawing.Size(60, 28);
            this.butThoat.TabIndex = 6;
            this.butThoat.Text = "Thoát";
            this.butThoat.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            this.butThoat.Click += new System.EventHandler(this.butThoat_Click);
            // 
            // butIn
            // 
            this.butIn.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.butIn.ForeColor = System.Drawing.Color.Navy;
            this.butIn.Image = ((System.Drawing.Image)(resources.GetObject("butIn.Image")));
            this.butIn.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.butIn.Location = new System.Drawing.Point(114, 110);
            this.butIn.Name = "butIn";
            this.butIn.Size = new System.Drawing.Size(60, 28);
            this.butIn.TabIndex = 5;
            this.butIn.Text = "In";
            this.butIn.Click += new System.EventHandler(this.butIn_Click);
            // 
            // butXem
            // 
            this.butXem.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.butXem.ForeColor = System.Drawing.Color.Navy;
            this.butXem.Image = ((System.Drawing.Image)(resources.GetObject("butXem.Image")));
            this.butXem.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.butXem.Location = new System.Drawing.Point(35, 110);
            this.butXem.Name = "butXem";
            this.butXem.Size = new System.Drawing.Size(60, 28);
            this.butXem.TabIndex = 4;
            this.butXem.Text = "  Xem";
            this.butXem.Click += new System.EventHandler(this.butXem_Click);
            // 
            // frmDanhSachConCB
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(284, 159);
            this.Controls.Add(this.label2);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.lsbChonTuoi);
            this.Controls.Add(this.butThoat);
            this.Controls.Add(this.butIn);
            this.Controls.Add(this.butXem);
            this.Controls.Add(this.groupBox1);
            this.ForeColor = System.Drawing.Color.Navy;
            this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
            this.Name = "frmDanhSachConCB";
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "Danh sách con CB - CNV";
            this.Load += new System.EventHandler(this.frmDanhSachConCB_Load);
            this.groupBox1.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)(this.lsbChonTuoi)).EndInit();
            this.ResumeLayout(false);

		}
		#endregion

		private void butThoat_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}
		private void print(bool prn)
		{
			try
			{
				string btdk="";
				if(rdbLonHonBang.Checked)
					btdk=rdbLonHonBang.Text;
				if(rdbLonNhoBang.Checked)
					btdk=rdbLonNhoBang.Text;
				if(rdbBang.Checked)
					btdk=rdbBang.Text;
                sql = "select case when gc.madt in ('C1','C2') then gc.madt else '' end AS Con,";
                sql += "gc.htendtg AS HoTenC, l.manv, trim(ho)||' '||trim(ten) AS HoTenCM,";
                sql += "to_char(now(),'dd') as Ngay_t,to_char(now(),'mm') as Thang,to_char(now(),'yyyy') as Nam,";
                sql += "gc.namsinh,gc.quequan,gc.nghenghiep, gc.ghichu, l.madv, bp.tenbp, to_number(to_char(now(),'yyyy'),'9999S')-to_number(case when gc.namsinh<>'' then gc.namsinh else '0' end,'9999S') AS TuoiCon ";
                sql += "from " + m_user + ".giacanh gc inner join " + m_user + ".llnv l on gc.manv = l.manv ";
                sql += "join " + m_user + ".bophan bp on l.madv = bp.madv ";
                sql += " inner join "+m_user+".hopdong hd on l.manv=hd.manv";
                sql += " inner join "+m_user+".max_lan ml on hd.manv=ml.manv";
                sql += " where hd.ngaynghi is null and to_number(to_char(now(),'yyyy'),'9999S')-to_number(case when gc.namsinh<>'' then gc.namsinh else '0' end,'9999S') " + btdk + " " + lsbChonTuoi.Value.ToString();
                sql += " and gc.madt in ('C1','C2') and hd.lan=ml.lan ";
                sql += "group by case when gc.madt in ('C1','C2') then gc.madt else '' end, gc.htendtg, l.manv, trim(ho)||' '||trim(ten),";
                sql += "gc.namsinh, gc.ghichu,gc.quequan,gc.nghenghiep, l.madv, bp.tenbp,to_char(now(),'dd') ,to_char(now(),'mm') ,to_char(now(),'yyyy') ";
                sql += " order by l.manv asc";    
				ds=mDB.get_data(sql);
                ds.WriteXml("..\\xml\\h_DanhsachConCBCNV.xml", XmlWriteMode.WriteSchema);
				if (ds!=null)
				{
                    title = lan.Change_language_MessageText("DANH SÁCH CON CB CNV TÍNH ĐẾN THÁNG ")+DateTime.Now.Month.ToString().PadLeft(2,'0');
	                title+="/"+DateTime.Now.Year.ToString();
                    ReportName = "h_DanhsachConCBCNV.rpt";
                    frmReport f = new frmReport(mDB, ds, title, ReportName, false,user_dn);
                    f.ShowDialog(this);
				}
				else
					MessageBox.Show(lan.Change_language_MessageText("Chưa có dữ liệu"),lan.Change_language_MessageText("Thông Báo"));
			}
			catch{}
		}

		private void butXem_Click(object sender, System.EventArgs e)
		{
			try
			{
				print(false);
			}
			catch{}
		}

		private void butIn_Click(object sender, System.EventArgs e)
		{
			print(true);
		}

        private void frmDanhSachConCB_Load(object sender, EventArgs e)
        {
            m_user = mDB.user;
        }

        private void lsbChonTuoi_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                SendKeys.Send("{Tab}");	
        }

        private void rdbLonHonBang_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                SendKeys.Send("{Tab}");	
        }

        private void rdbLonNhoBang_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                SendKeys.Send("{Tab}");	
        }

        private void rdbBang_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                SendKeys.Send("{Tab}");	
        }
	}
}
